//产品第一层
var express = require('express');
var router = express.Router();

//引入第二层数据
const { getInsures, addInsures, delInsures, getInsuresById, updateInsures } = require('../service/insuresService')

//获取保险产品数据
router.get('/getInsures', async function (req, res, next) {

    const data = await getInsures(req.query)
    res.send(data)
})

//添加保险产品
router.post('/addInsures', async function (req, res, next) {
    const data = await addInsures(req.body)
    res.send(data)
})

//根据_id删除保险产品
router.post('/delInsures', async function (req, res, next) {
    const data = await delInsures(req.body, { delete: true })
    res.send(data)
})

//获取待修改产品数据
router.get(`/:_id`, async function (req, res, next) {

    const data = await getInsuresById(req.params)
    res.send(data)
})

//修改产品数据
router.post('/updateInsures', async function (req, res, next) {
    const data = await updateInsures(req.body)
    res.send(data)
})

module.exports = router;
